package com.ruoyi.project.notice.type.service;

import com.ruoyi.common.constant.UserConstants;
import com.ruoyi.common.utils.text.Convert;
import com.ruoyi.project.notice.type.domain.NoticeType;
import com.ruoyi.project.notice.type.mapper.NoticeTypeMapper;
import com.ruoyi.project.system.notice.domain.Notice;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class NoticeTypeServiceImpl implements NoticeTypeService {

    @Autowired
    private NoticeTypeMapper noticeTypeMapper;

    @Override
    public List<NoticeType> findAll(NoticeType noticeType) {
        return noticeTypeMapper.selectMore(noticeType);
    }

    @Override
    public List<NoticeType> findAll() {
        return noticeTypeMapper.selectAll();
    }

    @Override
    public String checkTypeNameUnique(NoticeType noticeType) {

       NoticeType type= noticeTypeMapper.selectOne(noticeType);

       if(type!=null){
           return UserConstants.TYPE_NAME_NOT_UNIQUE;
       }
        return UserConstants.TYPE_NAME_UNIQUE;
    }

    @Override
    public int insertPost(NoticeType noticeType) {

        return noticeTypeMapper.insert(noticeType);
    }

    @Override
    public NoticeType selectTypeById(Long tid) {

        return noticeTypeMapper.selectById(tid);
    }

    @Override
    public int updateType(NoticeType noticeType) {
        return noticeTypeMapper.update(noticeType);
    }

    @Override
    public int deletePostByIds(String ids) {

        Long[] typeIDs = Convert.toLongArray(ids);

        return noticeTypeMapper.deleteTypeByIds(typeIDs);
    }
}
